home *** CD-ROM | disk | FTP | other *** search
- Path: newsbf02.news.aol.com!not-for-mail
- From: mike1r@aol.com (Mike1R)
- Newsgroups: comp.lang.c++
- Subject: Overloaded methods and base classes
- Date: 16 Jan 1996 11:06:11 -0500
- Organization: America Online, Inc. (1-800-827-6364)
- Sender: root@newsbf02.news.aol.com
- Message-ID: <4dgidj$4gk@newsbf02.news.aol.com>
- Reply-To: mike1r@aol.com (Mike1R)
- NNTP-Posting-Host: newsbf02.mail.aol.com
-
- I've got a somewhat interesting C++ question. I can't find any reference
- to this case in Ellis and Stroustrup.
-
- Given the following:
-
- class A
- {
- public:
- virtual void M(void) const;
- };
-
- class B : public A
- {
- public:
- virtual void M(void); // This overloads A::M since not const
- };
-
- class C
- {
- public:
- void foo( A* theA );
- };
-
- void C::foo( A* theA ) // theA is of class B
- {
- theA->M();
- }
-
- When compiling, the Mac MetroWerks PowerPC CW5 compiler gives a warning
- that B::M hides A::M. This warning is expected. However, the compiler
- generates code such that C::foo() calls A::M() rather than B::M().
-
- Is this a proper C++ implementation, is it a compiler bug, or is it
- implementation dependent? Would the result be different if M() were not a
- virtual function?
-
- I don't normally monitor this group, so would please copy all responses to
- my e-mail address mike1@aol.com. Thanks.
-